﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FloodFree.Web.Areas.Api.ViewModels;
using System.Web.Security;

namespace FloodFree.Web.Areas.Api.Controllers
{
    public class SessionsController : Controller
    {
        
        [HttpPost]
        public JsonResult Create(LoginViewModel vm)
        {
            try
            {
                if (Membership.ValidateUser(vm.Username, vm.Password))
                {
                    return Json(new { Code = 1,
                        Message = "Login efetuado com sucesso" 
                    }, JsonRequestBehavior.AllowGet);
                }
               

                return Json(new { Code = -1,
                                   Message = "Invalid username or password" 
                        }, JsonRequestBehavior.AllowGet);
            }
            catch
            {
                return Json(new { Code = -1,
                    Message = "Erro ao tentar efetuar login" 
                }, JsonRequestBehavior.AllowGet);
            }
        }
        
        
    }
}
